package cn.edu.nwsuaf.examcenter.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import cn.edu.nwsuaf.examcenter.pojo.College;
import cn.edu.nwsuaf.examcenter.pojo.Grade;
import cn.edu.nwsuaf.examcenter.pojo.Major;
import cn.edu.nwsuaf.examcenter.pojo.Sclass;
import cn.edu.nwsuaf.examcenter.pojo.Student;
import cn.edu.nwsuaf.examcenter.service.*;

@Controller
@RequestMapping(value="/student")
public class StudentController {
	@Resource(name="studentService")
	private StudentService studentService;
	
	@Resource(name="collegeService")
	private CollegeService collegeService;
	
	@Resource(name="majorService")
	private MajorService majorService;
	
	@Resource(name="gradeService")
	private GradeService gradeService;
	
	@Resource(name="sclassService")
	private SclassService SclassService;
	
	/****
	 * 多级联动
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/loadCollege")
	public List<College> jsonLoadCollege(){
		return collegeService.jsonLoadCollege();
	}
	@ResponseBody
	@RequestMapping(value="/json/loadMajor/{collegeNo}")
	public List<Major> jsonLoadMajor(@PathVariable(value="collegeNo")String collegeNo){
		return majorService.jsonLoadMajor(collegeNo);
	}
	@ResponseBody
	@RequestMapping(value="/json/loadGrade/{majorNo}")
	public List<Grade> jsonLoadGrade(@PathVariable(value="majorNo")String majorNo){
		return gradeService.jsonLoadGrade(majorNo);
	}
	@ResponseBody
	@RequestMapping(value="/json/loadSclass/{gradeNo}")
	public List<Sclass> jsonLoadSclass(@PathVariable(value="gradeNo")String gradeNo){
		return SclassService.jsonLoadSclass(gradeNo);
	}
	/*-----------------------------------分割线----------------------------------------*/
	
	@ResponseBody
	@RequestMapping(value="/addStudent",method=RequestMethod.POST)
	public String addStudent(@ModelAttribute Student student){
		return studentService.addStudent(student);
	}
	
	
	@ResponseBody
	@RequestMapping(value="/deleteStudent/{studentNo}")
	public String deleteStudent(@PathVariable(value="studentNo")String studentNo){
		return studentService.deleteStudent(studentNo);
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteStudentList")
	public String deleteStudentList(@RequestParam(value="array")String array){
		return studentService.deleteStudentList(array);
	}
	
	@RequestMapping(value="/loadStudent")
	public String loadStudent(@RequestParam(value="key",required=false)String key, 
			@RequestParam(value="p",required=false)String p, 
			ModelMap modelMap){
		studentService.loadStudent(modelMap);
		return "exam/student-list";
	}
}
